<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>小艾爱跑 | 成绩检测打印</title>
<link rel="stylesheet" href="http://static-paobuqu-com.oss-cn-hangzhou.aliyuncs.com/css%2Fbootstrap.min.css">
<link rel="shortcut icon" type="image/ico" href="web/favicon.ico">

<style type="text/css">
    
    body,td,th {font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 14px;font-weight: bold;color: #1d1007; line-height:24px}

    h2 {
        margin-top: 28px;
        margin-bottom: 0px;
    }

    table{
        border-collapse: collapse;
        width: 100%;
        text-align: center;
    }
    td{
        border:1px solid #000;
        padding: 2px;
    }


</style>

</head>
<body>
    <div class="container">
        <h2>
            <span id="race_name"></span>
            <span>成绩</span>
            <br>        
        </h2>
        <div id="table"></div>
        <div style="float: right">
            <br>
            裁判长签字：________________
            <br>
            日期：
            <span id="date"></span>
            <br>
            <br>
            <br>
        </div>
    </div>
</body>
</html>
<script type="text/javascript">
    //获取数据信息
    var obj = JSON.parse(localStorage.getItem('checkDataForPrint'));

    //表格信息
    var checkData = obj.checkData;
    //日期
    var myDate = new Date(); 
    document.getElementById('date').innerHTML = myDate.getFullYear() + '/' + (myDate.getMonth() + 1) + '/' + myDate.getDate();
    console.log(checkData);
    checkData.forEach(function(element1){
    	createTable(element1);
    })
    //比赛名称
    document.getElementById('race_name').innerHTML = obj.race_name;

    function createTable(element1){

        var div = document.getElementById("table"); 
        //创建table
        var table = document.createElement("table");

        //个人，单程，定距
        // 自定义
        
        	element1.forEach(function(element2){
        		console.log(element2.cp);
	        	//title
	            //创建一行
	            var row = table.insertRow();
	            var cell = row.insertCell();
	            cell.innerHTML='选手号';
	            cell = row.insertCell();
	            cell.innerHTML='姓名';
	            cell = row.insertCell();
	            cell.innerHTML='性别';
	            element2.cp.forEach(function(element3){
		     		cell = row.insertCell();
					cell.innerHTML=element3.cp_name;
					//cell = row.insertCell();
					//cell.innerHTML='通过时间';	
	            })
	            
	        	
	            //创建一行
	            var row = table.insertRow();
	            // ["bib","选手号"]
	            var cell = row.insertCell();
	            cell.innerHTML=element2.bib;
	            // ["runnerName","姓名"]
	            cell = row.insertCell();
	            cell.innerHTML=element2.name;
	            // ["sex","性别"]
	            cell = row.insertCell();
	            //性别显示
	            if (element2.sex == 'male') {
	                //男
	                cell.innerHTML = '男子';
	            } else if (element2.sex == 'female') {
	                //女
	                cell.innerHTML= '女子';
	            } else {
	            	cell.innerHTML= '';
	            }
	            element2.cp.forEach(function(element3){
	        		// ["cpName","计时点名称"]
	                //cell = row.insertCell();
	                //cell.innerHTML=element4.cp_name;
	                // ["leaveTime","通过时间"]
	                cell = row.insertCell();
	                cell.innerHTML=element3.arrive_time;	
	            })
        	})

        div.appendChild(table);
        div.appendChild(document.createElement("p"));
    }
</script> 